package com.commit.utils;


import com.commit.domain.ActiveUser;
import com.commit.domain.Likes;
import com.commit.domain.User;
import com.commit.mapper.LikeMapper;
import com.commit.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class SysUtils {
    @Autowired
    private LikeMapper likesMapper;
    @Autowired
    private UserMapper userMapper;

    public static SysUtils sysUtils;

    @PostConstruct
    public void init() {
        sysUtils = this;
    }

    /**
     * @param answerId
     * @return
     */
    public static Boolean isLikes(Integer answerId){
        boolean flag = false;
        ActiveUser user = UserUtils.getUser();
        if(user != null) {
            Likes likes = sysUtils.likesMapper.findOne(user.getId(),answerId);
            if (likes != null) {
                flag = true;
            }
        }
        return flag;
    }

    /**
     * 获取用户
     */
    public static User getUser(Integer userId) {
        return sysUtils.userMapper.findById(userId);
    }

    /**
     * 是否收藏
     */


}